package com.jiang.text;

import redis.clients.jedis.Jedis;

import java.util.concurrent.TimeUnit;

public class Redislock {

    public static boolean getlock(String biz) {
        Jedis jedis = new Jedis("127.0.0.1",6379,10000);

        while (true) {
            long res = jedis.setnx(biz, "success");
            jedis.expire(biz,10);
            if (res < 1) {
                try {
                    Thread.sleep(500);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }else {
                return true;
            }
        }
    }
    public static void kaisuo(String biz){
        Jedis jedis=new Jedis("127.0.0.1",6379);
        jedis.del(biz);
    }
}
